package cn.shangqizhenshuai.sqiot.Serivce.impl;

import cn.shangqizhenshuai.sqiot.Serivce.EquipmentService;
import cn.shangqizhenshuai.sqiot.entity.EA;
import cn.shangqizhenshuai.sqiot.entity.EAExample;
import cn.shangqizhenshuai.sqiot.entity.Equipment;
import cn.shangqizhenshuai.sqiot.entity.EquipmentExample;
import cn.shangqizhenshuai.sqiot.mapper.EAMapper;
import cn.shangqizhenshuai.sqiot.mapper.EquipmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("equipmentService")
public class EquipmentServiceImpl implements EquipmentService {

    @Autowired
    private EquipmentMapper equipmentMapper;
    @Autowired
    private EAMapper eaMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Equipment> get_list_by_area_id(int id) {
        List<Equipment> equipment = equipmentMapper.selectequipmentByaid(id);
        return equipment;
    }
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int update_flag_by_id(int id, int flag) {
        return equipmentMapper.UpdatEpreameatByequipmentId(id, flag);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Equipment> get_list() {
        EquipmentExample equipmentExample = new EquipmentExample();
        EquipmentExample.Criteria criteria = equipmentExample.createCriteria().andFlagEqualTo(0);
        return  equipmentMapper.selectByExample(equipmentExample);
    }

    @Override
    public Equipment get_by_id(int id) {
        EquipmentExample equipmentExample = new EquipmentExample();
        EquipmentExample.Criteria criteria = equipmentExample.createCriteria().andIdEqualTo(id);
        return  equipmentMapper.selectByExample(equipmentExample).get(0);

    }

    @Override
    public Equipment get_like_by_statrurl(String statrurl) {
        EquipmentExample equipmentExample = new EquipmentExample();
        EquipmentExample.Criteria criteria = equipmentExample.createCriteria().andStatrurlLike("%"+statrurl);
        return  equipmentMapper.selectByExample(equipmentExample).get(0);
    }

    @Override
    public Map<Integer, Double> get_r_value(String eids) {
        return equipmentMapper.get_r_value(eids);
    }
}
